package com.fmdc.ehtp.gi.dao;

import java.io.Serializable;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.fmdc.ehtp.gi.entity.Action;
/**
 *  This is provide AS IS without any Guarantee of any kind
 *  Author: Guddu from IQTF
 *  Date: 25th June 2010
 */
@Transactional
@Repository
public class HibernateDAO {
	
	private SessionFactory sessionFactory = null;

  public void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory;
  }
  public void test()
  {

	  Action a = new Action();
	  System.out.println("ohhhhh"+saveObject(a));


	  
  }


  public Object saveObject(Object obj) {
    return sessionFactory.getCurrentSession().save(obj);
  }

  public void updateObject(Long id, Object obj) {
      sessionFactory.getCurrentSession().update(Long.toString(id), obj);
  }

  public void deleteObject(Object obj) {
      sessionFactory.getCurrentSession().delete(obj);
  }
  @SuppressWarnings("rawtypes")
public Object fetch(Class clz, Serializable id) {
      return sessionFactory.getCurrentSession().get(clz, id);
  }
  /**
   * This method is just to help in printing
   * out the Transaction that is used across
   * the operations.
   * @return Session
   */
  public Session getCurrentSession() {
      return sessionFactory.getCurrentSession();
  }



  public static void main(String args[])
	{
	  	ApplicationContext clsCtx =
		      new FileSystemXmlApplicationContext("D:\\projetkarama\\workspace\\projetDeRealisation\\WebContent\\WEB-INF\\application-context.xml");
	  			HibernateDAO hibernateDAO = (HibernateDAO) clsCtx.getBean("hibernateDAO");
	  			hibernateDAO.test();



	}
}
